package com.goods.controller.business;

import com.goods.business.service.OutStockService;
import com.goods.common.model.business.OutStock;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.InStockDetailVO;
import com.goods.common.vo.business.OutStockDetailVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/business/outStock")
public class OutStockController {

    @Resource
    private OutStockService outStockService;

    @GetMapping("/findOutStockList")
    public ResponseBean findOutStockList(Integer pageNum, Integer pageSize, Integer status,Integer type,String outNum){
        Map map = outStockService.findOutStockList(pageNum,pageSize,status,type,outNum);
        return ResponseBean.success(map);
    }

    //查看入库单明细
    @GetMapping("/detail/{id}")
    public ResponseBean detail(@PathVariable Long id, Integer pageNum){
        OutStockDetailVO outStockDetailVO = outStockService.detail(id);
        return ResponseBean.success(outStockDetailVO);
    }

    //移入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        int i = outStockService.remove(id);
        if (i != 0) {
            return ResponseBean.success();
        }else {
            return ResponseBean.error("移入回收站失败");
        }
    }

    //移出回收站
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        int i = outStockService.back(id);
        if (i != 0) {
            return ResponseBean.success();
        }else {
            return ResponseBean.error("移出回收站失败");
        }
    }

    //删除
    @GetMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        int i = outStockService.delete(id);
        if (i != 0) {
            return ResponseBean.success();
        }else {
            return ResponseBean.error("删除失败");
        }
    }

    @PostMapping("/addOutStock")
    public ResponseBean addOutStock(@RequestBody Map map){
        outStockService.addIntoStock(map);
        return ResponseBean.success();
    }

    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        int i = outStockService.publish(id);
        if (i != 0) {
            return ResponseBean.success();
        }else {
            return ResponseBean.error("审核失败");
        }
    }


}
